package cn.anecansaitin.not_enough_harness.common;

import cn.anecansaitin.not_enough_harness.NotEnoughHarness;
import cn.anecansaitin.not_enough_harness.common.capability.SprintableHarnessHandler;
import cn.anecansaitin.not_enough_harness.common.capability.harness_attribute.DataMapHarnessAttributeHandler;
import cn.anecansaitin.not_enough_harness.common.capability.harness_attribute.HarnessAttributeHandler;
import cn.anecansaitin.not_enough_harness.common.capability.harness_capability.CraftingTableHarnessHandler;
import cn.anecansaitin.not_enough_harness.common.capability.harness_capability.HarnessCapabilityHandler;
import cn.anecansaitin.not_enough_harness.common.capability.harness_capability.RushTriggerHarnessHandler;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.capabilities.ItemCapability;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;

@EventBusSubscriber(modid = NotEnoughHarness.MOD_ID)
public class ModCapabilities {
    public static final ItemCapability<HarnessAttributeHandler, Void> HARNESS_ATTRIBUTE_HANDLER =
            ItemCapability.createVoid(
                    ResourceLocation.fromNamespaceAndPath(NotEnoughHarness.MOD_ID, "harness_attribute_handler"),
                    HarnessAttributeHandler.class
            );
    public static final ItemCapability<HarnessCapabilityHandler, Void> HARNESS_CAPABILITY_HANDLER =
            ItemCapability.createVoid(
                    ResourceLocation.fromNamespaceAndPath(NotEnoughHarness.MOD_ID, "harness_capability_handler"),
                    HarnessCapabilityHandler.class
            );

    @SubscribeEvent
    public static void registerCapabilities(RegisterCapabilitiesEvent event) {
        event.registerItem(HARNESS_ATTRIBUTE_HANDLER, dataMapHandler,
                ModItems.VERTILEAP_HARNESS,
                ModItems.CLOUD_WALKER_HARNESS,
                ModItems.RUSH_HARNESS);

        event.registerItem(HARNESS_CAPABILITY_HANDLER, (a,b) -> SprintableHarnessHandler.INSTANCE,
                ModItems.JET_HARNESS,
                ModItems.BOX_HARNESS);
        event.registerItem(HARNESS_ATTRIBUTE_HANDLER, (a,b) -> SprintableHarnessHandler.INSTANCE,
                ModItems.JET_HARNESS,
                ModItems.BOX_HARNESS);

        event.registerItem(HARNESS_CAPABILITY_HANDLER, (a, b) -> RushTriggerHarnessHandler.INSTANCE,
                ModItems.RUSH_HARNESS);

        event.registerItem(HARNESS_CAPABILITY_HANDLER, (a, b) -> CraftingTableHarnessHandler.INSTANCE,
                ModItems.CRAFTING_TABLE_HARNESS);
    }

    private static final ICapabilityProvider<ItemStack, Void, HarnessAttributeHandler> dataMapHandler = (item, v) -> DataMapHarnessAttributeHandler.INSTANCE;
}
